

local spawnInfo=nil
local readySpawn=false

function StartSpawn()
    --print("creep..StartSpawn")
    local creeps= Unit:GetRandomSpawnCreep(RandomInt(spawnInfo.minCount,spawnInfo.maxCount))
    for _,value in pairs(creeps) do
         --print(value)
        local unit= CreateUnitByName( value , thisEntity:GetAbsOrigin() + RandomVector( RandomFloat( 0, 200 ) ), true, nil, nil, DOTA_TEAM_NEUTRALS )
        if unit==nil then
            print(value)
        end
        local lv=unit:GetLevel()
        local hp=SpawnConfig.hp*SpawnConfig.hpRate^(lv-1)
        local attack=SpawnConfig.attack*SpawnConfig.attackRate^(lv)
        unit:SetMinimumGoldBounty(0);
        unit:SetMaximumGoldBounty(0);
        unit:SetMana(lv*200);
        unit:SetDeathXP(0)
        unit:SetMaxHealth(hp)
        unit:SetHealth(hp)
        unit:SetBaseMaxHealth(hp)
        unit:SetBaseDamageMax(attack)
        unit:SetBaseDamageMin(attack)
        unit:SetPhysicalArmorBaseValue(1)
    end
    return 5
end



function OnTriggerThink_Timer()
    if spawnInfo==nil then
        if type(SpawnCreepConfig) == "table"  then
            spawnInfo= SpawnCreepConfig["npc_dota_spawner"]
        end
        return 3
    end
    local count = FindUnitsInRadius(DOTA_TEAM_NEUTRALS,thisEntity:GetAbsOrigin(),nil, 1800,DOTA_UNIT_TARGET_TEAM_FRIENDLY, DOTA_UNIT_TARGET_ALL, DOTA_UNIT_TARGET_FLAG_NONE, FIND_ANY_ORDER, false )
    if count ~=nil and #count~=0 then
        return 3
    else
        if readySpawn==true then
            readySpawn=false
            return StartSpawn()
        else
            readySpawn=true
            local intervalTime=GameRules:GetDOTATime(false,false)

            if intervalTime<=spawnInfo.firstRefreshTime then
                intervalTime=spawnInfo.firstRefreshTime-intervalTime
            else
                intervalTime=spawnInfo.intervalTime
            end
            return intervalTime
        end
    end
    return 3
end

thisEntity:SetThink( "OnTriggerThink_Timer", 6 )